/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * SalesOrderFrame.java
 *
 * Created on Feb 8, 2011, 1:18:34 PM
 */

package gbbmgmt;

import java.util.*;
import org.jdesktop.application.Action;
import javax.swing.JOptionPane;
import java.sql.*;

/**
 *
 * @author dchapman
 */
public class SalesOrderFrame extends javax.swing.JFrame {

    public ArrayList<String[]> SalesOrders;

    /** Creates new form SalesOrderFrame */
    public SalesOrderFrame() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel10 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jTextFieldSODate = new javax.swing.JTextField();
        jSeparator2 = new javax.swing.JSeparator();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jLabel7 = new javax.swing.JLabel();
        jTextFieldCustName = new javax.swing.JTextField();
        jTextFieldSOID = new javax.swing.JTextField();
        jSeparator1 = new javax.swing.JSeparator();
        jLabel2 = new javax.swing.JLabel();
        jSeparator4 = new javax.swing.JSeparator();
        jLabel1 = new javax.swing.JLabel();
        jButtonCustLast = new javax.swing.JButton();
        jButtonExit = new javax.swing.JButton();
        jButtonCustNext = new javax.swing.JButton();
        jButtonSOAdd = new javax.swing.JButton();
        jButtonCustFirst = new javax.swing.JButton();
        jButtonCustPrev = new javax.swing.JButton();
        jButtonCustomerInfo = new javax.swing.JButton();
        jTextFieldSODueDate = new javax.swing.JTextField();
        jCheckBoxSOPaid = new javax.swing.JCheckBox();
        jLabel3 = new javax.swing.JLabel();
        jTextFieldCheckNo = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jTextFieldNotes = new javax.swing.JTextField();
        jButtonUpdate = new javax.swing.JButton();
        jButtonSearch = new javax.swing.JButton();
        jTextFieldSNum = new javax.swing.JTextField();
        jLabelOverDue = new javax.swing.JLabel();
        jButtonPrintSO = new javax.swing.JButton();
        jComboBoxSONum = new javax.swing.JComboBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setName("Form"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(gbbmgmt.GBBMGMTApp.class).getContext().getResourceMap(SalesOrderFrame.class);
        jLabel10.setText(resourceMap.getString("jLabel10.text")); // NOI18N
        jLabel10.setName("jLabel10"); // NOI18N

        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N

        jTextFieldSODate.setEditable(false);
        jTextFieldSODate.setName("jTextFieldSODate"); // NOI18N

        jSeparator2.setName("jSeparator2"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jTextArea1.setColumns(20);
        jTextArea1.setEditable(false);
        jTextArea1.setRows(5);
        jTextArea1.setName("jTextArea1"); // NOI18N
        jScrollPane1.setViewportView(jTextArea1);

        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        jTextFieldCustName.setEditable(false);
        jTextFieldCustName.setName("jTextFieldCustName"); // NOI18N

        jTextFieldSOID.setEditable(false);
        jTextFieldSOID.setName("jTextFieldSOID"); // NOI18N

        jSeparator1.setName("jSeparator1"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jSeparator4.setName("jSeparator4"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(gbbmgmt.GBBMGMTApp.class).getContext().getActionMap(SalesOrderFrame.class, this);
        jButtonCustLast.setAction(actionMap.get("LastRecord")); // NOI18N
        jButtonCustLast.setText(resourceMap.getString("jButtonCustLast.text")); // NOI18N
        jButtonCustLast.setName("jButtonCustLast"); // NOI18N

        jButtonExit.setAction(actionMap.get("ExitSO")); // NOI18N
        jButtonExit.setText(resourceMap.getString("jButtonExit.text")); // NOI18N
        jButtonExit.setName("jButtonExit"); // NOI18N

        jButtonCustNext.setAction(actionMap.get("GetNext")); // NOI18N
        jButtonCustNext.setText(resourceMap.getString("jButtonCustNext.text")); // NOI18N
        jButtonCustNext.setName("jButtonCustNext"); // NOI18N

        jButtonSOAdd.setAction(actionMap.get("NewSO")); // NOI18N
        jButtonSOAdd.setText(resourceMap.getString("jButtonSOAdd.text")); // NOI18N
        jButtonSOAdd.setName("jButtonSOAdd"); // NOI18N

        jButtonCustFirst.setAction(actionMap.get("FirstRecord")); // NOI18N
        jButtonCustFirst.setText(resourceMap.getString("jButtonCustFirst.text")); // NOI18N
        jButtonCustFirst.setName("jButtonCustFirst"); // NOI18N

        jButtonCustPrev.setAction(actionMap.get("GetPrev")); // NOI18N
        jButtonCustPrev.setText(resourceMap.getString("jButtonCustPrev.text")); // NOI18N
        jButtonCustPrev.setName("jButtonCustPrev"); // NOI18N

        jButtonCustomerInfo.setAction(actionMap.get("ShoCustomer")); // NOI18N
        jButtonCustomerInfo.setText(resourceMap.getString("jButtonCustomerInfo.text")); // NOI18N
        jButtonCustomerInfo.setName("jButtonCustomerInfo"); // NOI18N

        jTextFieldSODueDate.setEditable(false);
        jTextFieldSODueDate.setName("jTextFieldSODueDate"); // NOI18N

        jCheckBoxSOPaid.setText(resourceMap.getString("jCheckBoxSOPaid.text")); // NOI18N
        jCheckBoxSOPaid.setName("jCheckBoxSOPaid"); // NOI18N

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jTextFieldCheckNo.setText(resourceMap.getString("jTextFieldCheckNo.text")); // NOI18N
        jTextFieldCheckNo.setName("jTextFieldCheckNo"); // NOI18N

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jTextFieldNotes.setText(resourceMap.getString("jTextFieldNotes.text")); // NOI18N
        jTextFieldNotes.setName("jTextFieldNotes"); // NOI18N

        jButtonUpdate.setAction(actionMap.get("UpdateSO")); // NOI18N
        jButtonUpdate.setText(resourceMap.getString("jButtonUpdate.text")); // NOI18N
        jButtonUpdate.setName("jButtonUpdate"); // NOI18N

        jButtonSearch.setAction(actionMap.get("SearchSO")); // NOI18N
        jButtonSearch.setText(resourceMap.getString("jButtonSearch.text")); // NOI18N
        jButtonSearch.setName("jButtonSearch"); // NOI18N

        jTextFieldSNum.setText(resourceMap.getString("jTextFieldSNum.text")); // NOI18N
        jTextFieldSNum.setName("jTextFieldSNum"); // NOI18N

        jLabelOverDue.setForeground(resourceMap.getColor("jLabelOverDue.foreground")); // NOI18N
        jLabelOverDue.setText(resourceMap.getString("jLabelOverDue.text")); // NOI18N
        jLabelOverDue.setName("jLabelOverDue"); // NOI18N

        jButtonPrintSO.setAction(actionMap.get("PrintSOrder")); // NOI18N
        jButtonPrintSO.setText(resourceMap.getString("jButtonPrintSO.text")); // NOI18N
        jButtonPrintSO.setName("jButtonPrintSO"); // NOI18N

        jComboBoxSONum.setName("jComboBoxSONum"); // NOI18N
        jComboBoxSONum.addPopupMenuListener(new javax.swing.event.PopupMenuListener() {
            public void popupMenuCanceled(javax.swing.event.PopupMenuEvent evt) {
            }
            public void popupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {
                jComboBoxSONumPopupMenuWillBecomeInvisible(evt);
            }
            public void popupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 626, Short.MAX_VALUE)
            .addComponent(jSeparator2, javax.swing.GroupLayout.DEFAULT_SIZE, 626, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(jLabel8))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTextFieldSOID, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addComponent(jTextFieldSODate, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel7)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextFieldSODueDate, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jTextFieldCustName, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 379, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(10, 10, 10)
                                .addComponent(jLabelOverDue))
                            .addComponent(jButtonCustomerInfo))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel10)
                .addContainerGap(549, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jCheckBoxSOPaid)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextFieldCheckNo, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextFieldNotes, javax.swing.GroupLayout.DEFAULT_SIZE, 356, Short.MAX_VALUE))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 606, Short.MAX_VALUE))
                .addContainerGap())
            .addComponent(jSeparator4, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 626, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButtonSOAdd)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonPrintSO)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 154, Short.MAX_VALUE)
                .addComponent(jButtonUpdate)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonExit)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jComboBoxSONum, javax.swing.GroupLayout.PREFERRED_SIZE, 144, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonSearch)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextFieldSNum, javax.swing.GroupLayout.DEFAULT_SIZE, 113, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addComponent(jButtonCustFirst)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonCustPrev)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonCustNext)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonCustLast)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jButtonCustPrev)
                    .addComponent(jButtonCustFirst)
                    .addComponent(jButtonCustNext)
                    .addComponent(jButtonCustLast)
                    .addComponent(jButtonSearch)
                    .addComponent(jTextFieldSNum, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jComboBoxSONum, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(8, 8, 8)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 5, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldSOID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addGap(9, 9, 9)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldCustName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2)
                    .addComponent(jButtonCustomerInfo))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldSODate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8)
                    .addComponent(jTextFieldSODueDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7)
                    .addComponent(jLabelOverDue))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 7, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(2, 2, 2)
                .addComponent(jLabel10)
                .addGap(2, 2, 2)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jCheckBoxSOPaid)
                    .addComponent(jLabel3)
                    .addComponent(jTextFieldCheckNo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4)
                    .addComponent(jTextFieldNotes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jButtonExit)
                        .addComponent(jButtonUpdate))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jButtonSOAdd)
                        .addComponent(jButtonPrintSO)))
                .addGap(14, 14, 14))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jComboBoxSONumPopupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {//GEN-FIRST:event_jComboBoxSONumPopupMenuWillBecomeInvisible
        // TODO add your handling code here:
        String Itm = jComboBoxSONum.getSelectedItem().toString();

        for(String s[] : SalesOrders){
            if (s[0].equals(Itm)) {
                DBA.openDBCon();
                DBA.GetSalesOrderData(s[0]);
                DBA.GetCustomerData(s[1]);
                DBA.closeDBCon();
            }
        }
        SetData();
    }//GEN-LAST:event_jComboBoxSONumPopupMenuWillBecomeInvisible

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new SalesOrderFrame().setVisible(true);
            }
        });
    }

    public void LoadList(){
        DBA.openDBCon();
        SalesOrders = DBA.RunSQLQuery("SELECT SOId,SOCust FROM SalesOrder");
        DBA.closeDBCon();

        for(String s[] : SalesOrders){
            jComboBoxSONum.addItem(s[0]);
        }    

        FirstRecord();
    }

    public void SetData(){
        long n = DBA.SOId;
        String mask = "i000000";
        String ds = Long.toString(n);
        String z = mask.substring(0,mask.length() - ds.length()) + ds;

        //Set up calendar.
        Calendar cal = Calendar.getInstance();
        cal.setTime(DBA.SODate);

        //Add appropriate time to calendar.
        cal.add(Calendar.DATE, DBA.CTerms);
        java.sql.Date due = new java.sql.Date(cal.getTime().getTime());

        //Get todays date.
        java.util.Date dt = new java.util.Date();
        java.sql.Date todaysdate = new java.sql.Date( dt.getTime());

        //Set text boxes.
        jTextFieldSOID.setText(z);
        jTextFieldCustName.setText(DBA.CName);
        jTextFieldSODate.setText(DBA.SODate.toString());
        jTextFieldSODueDate.setText(due.toString());
        jTextFieldCheckNo.setText(DBA.CheckNo);
        jTextFieldNotes.setText(DBA.CheckNotes);

        //Check if SO is over due or not.
        if ((todaysdate.after(due)) && !DBA.SOPaid){
            //Over due.
            jLabelOverDue.setVisible(true);
        } else {
            jLabelOverDue.setVisible(false);
        }

        //set check box.
        if(DBA.SOPaid){
            jCheckBoxSOPaid.setSelected(true);
        } else {
            jCheckBoxSOPaid.setSelected(false);
        }

        //Print out sales order.
        String SOOUT = DBA.GetSalesOrderString(DBA.SOCSV);
        SOOUT += "\nTotal Cost: $" + DBA.SOCCost;
        jTextArea1.setText(SOOUT);

    }

    @Action
    public void LastRecord() {
        jComboBoxSONum.setSelectedIndex(jComboBoxSONum.getItemCount()-1);

        String Itm = jComboBoxSONum.getSelectedItem().toString();

        for(String s[] : SalesOrders){
            if (s[0].equals(Itm)) {
                DBA.openDBCon();
                DBA.GetSalesOrderData(s[0]);
                DBA.GetCustomerData(s[1]);
                DBA.closeDBCon();
            }
        }
        SetData();
    }

    @Action
    public void FirstRecord() {
        jComboBoxSONum.setSelectedIndex(0);

        String Itm = jComboBoxSONum.getSelectedItem().toString();

        for(String s[] : SalesOrders){
            if (s[0].equals(Itm)) {
                DBA.openDBCon();
                DBA.GetSalesOrderData(s[0]);
                DBA.GetCustomerData(s[1]);
                DBA.closeDBCon();
            }
        }
        SetData();
    }

    @Action
    public void GetPrev() {
        if(jComboBoxSONum.getSelectedIndex()>=1){
            jComboBoxSONum.setSelectedIndex(jComboBoxSONum.getSelectedIndex()-1);
        }

        String Itm = jComboBoxSONum.getSelectedItem().toString();

        for(String s[] : SalesOrders){
            if (s[0].equals(Itm)) {
                DBA.openDBCon();
                DBA.GetSalesOrderData(s[0]);
                DBA.GetCustomerData(s[1]);
                DBA.closeDBCon();
            }
        }
        SetData();
    }

    @Action
    public void GetNext() {
        if(jComboBoxSONum.getSelectedIndex() <= (jComboBoxSONum.getItemCount()-2)){
            jComboBoxSONum.setSelectedIndex(jComboBoxSONum.getSelectedIndex()+1);
        }

        String Itm = jComboBoxSONum.getSelectedItem().toString();

        for(String s[] : SalesOrders){
            if (s[0].equals(Itm)) {
                DBA.openDBCon();
                DBA.GetSalesOrderData(s[0]);
                DBA.GetCustomerData(s[1]);
                DBA.closeDBCon();
            }
        }
        SetData();
    }

    @Action
    public void ExitSO() {
        dispose();
    }

    @Action
    public void SearchSO() {
        String Itm = jTextFieldSNum.getText();

        if (!Itm.equals("")){
            for(String s[] : SalesOrders){
                if (s[0].equals(Itm)) {
                    DBA.openDBCon();
                    DBA.GetSalesOrderData(s[0]);
                    DBA.GetCustomerData(s[1]);
                    DBA.closeDBCon();
                    jComboBoxSONum.setSelectedItem(Itm);
                    jTextFieldSNum.setText("");
                }
            }
            SetData();
        }
    }

    @Action
    public void ShoCustomer() {
        CustomerFrame newFrame = new CustomerFrame();
        newFrame.pack();
        newFrame.setLocation(250,250);
        newFrame.setVisible(true);
        newFrame.LoadList();
        newFrame.SelectEntry(jTextFieldCustName.getText());
    }

    @Action
    public void UpdateSO() {
        //Update Sales Order based on checkbox, check no, and notes.
        int response = JOptionPane.showConfirmDialog(null,
                "This will modify sales order data, continue?",
                "Warning",JOptionPane.WARNING_MESSAGE);

        if (response == 0){
            DBA.openDBCon();
            String SOID = jComboBoxSONum.getSelectedItem().toString();

            if(!jTextFieldCheckNo.getText().equals(DBA.CheckNo)){
                String query = "UPDATE SalesOrder SET CheckNo = '" +
                        jTextFieldCheckNo.getText() + "'WHERE SOId = '" +
                        SOID + "'";
                DBA.RunSQLUpdateQuery(query);
            }

            if(!jTextFieldNotes.getText().equals(DBA.CheckNotes)){
                String query = "UPDATE SalesOrder SET CheckNotes = '" +
                        jTextFieldNotes.getText() + "'WHERE SOId = '" +
                        SOID + "'";
                DBA.RunSQLUpdateQuery(query);
            }

            //update check boxes.

            if(jCheckBoxSOPaid.isSelected() && (!DBA.SOPaid)){
                String query = "UPDATE SalesOrder SET SOPaid = '1' WHERE SOId = '" +
                        SOID + "'";
                DBA.RunSQLUpdateQuery(query);
            } else if (!jCheckBoxSOPaid.isSelected() && (DBA.SOPaid)){
                String query = "UPDATE SalesOrder SET SOPaid = '0' WHERE SOId = '" +
                        SOID + "'";
                DBA.RunSQLUpdateQuery(query);
            }

            //Update the screen
            DBA.GetSalesOrderData(SOID);
            DBA.closeDBCon();

            SetData();

        }
    }

    @Action
    public void NewSO() {
        //TODO: Open new sales order frame.
    }

    @Action
    public void PrintSOrder() {

        String Itm = jComboBoxSONum.getSelectedItem().toString();

        for(String s[] : SalesOrders){
            if (s[0].equals(Itm)) {
                DBA.openDBCon();
                DBA.GetSalesOrderData(s[0]);
                DBA.closeDBCon();
            }
        }

        Global.PrintSalesOrderID = Integer.toString(DBA.SOId);

        PrintSalesOrder PSO = new PrintSalesOrder();
        PSO.PrintSO();
    }





    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonCustFirst;
    private javax.swing.JButton jButtonCustLast;
    private javax.swing.JButton jButtonCustNext;
    private javax.swing.JButton jButtonCustPrev;
    private javax.swing.JButton jButtonCustomerInfo;
    private javax.swing.JButton jButtonExit;
    private javax.swing.JButton jButtonPrintSO;
    private javax.swing.JButton jButtonSOAdd;
    private javax.swing.JButton jButtonSearch;
    private javax.swing.JButton jButtonUpdate;
    private javax.swing.JCheckBox jCheckBoxSOPaid;
    private javax.swing.JComboBox jComboBoxSONum;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabelOverDue;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator4;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextField jTextFieldCheckNo;
    private javax.swing.JTextField jTextFieldCustName;
    private javax.swing.JTextField jTextFieldNotes;
    private javax.swing.JTextField jTextFieldSNum;
    private javax.swing.JTextField jTextFieldSODate;
    private javax.swing.JTextField jTextFieldSODueDate;
    private javax.swing.JTextField jTextFieldSOID;
    // End of variables declaration//GEN-END:variables

}
